package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Chapter;
import com.atguigu.guli.service.edu.mapper.ChapterMapper;
import com.atguigu.guli.service.edu.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author leo
 * @since 2021-11-24
 */
@RestController
@RequestMapping("/admin/edu/chapter")

public class AdminChapterController {
    @Autowired
    ChapterService chapterService ;

    @GetMapping("getNestedChapter/{courseId}")
    public R getNestedChapter(@PathVariable String courseId) {
        List<Chapter> chapters = chapterService.getNestedChapter(courseId) ;
        return R.ok().data("items",chapters) ;
    }

    @PostMapping("save")
    public R save(@RequestBody Chapter chapter) {
        chapterService.save(chapter) ;
        return R.ok() ;
    }

    @DeleteMapping("delete/{courseId}")
    public R delete(@PathVariable String courseId) {
        chapterService.removeById(courseId) ;
        return R.ok() ;
    }

    @GetMapping("getById/{courseId}")
    public R update(@PathVariable String courseId) {
        Chapter chapter = chapterService.getById(courseId) ;
        return R.ok().data("item",chapter) ;
    }

    @PutMapping("update")
    public R update(@RequestBody Chapter chapter) {
        chapterService.updateById(chapter) ;
        return R.ok() ;
    }
}

